import utils from '@/utils/index'
import request from '@/utils/request'
import merchant from "./merchant"
import { useCommonStoreWithOut } from '../store/common'

export default {

  merchant,
  ecm: {
    posDevice: {
      verifyPosNoExits (params) {
        return request({
          url: '/app-api/ecm/app/pos-device/verifyPosNoExits',
          method: 'get',
          params
        })
      },
      bindPosDevice (data) {
        const querData = {
          id: undefined,
          posNo: undefined,
          deviceType: undefined,
          snNo: undefined,
          merchantId: undefined,
          merchantName: undefined,
          deviceModel: undefined,
          deviceManufacturer: undefined,
          appVersion: undefined,
          sysVersion: undefined,
          homeScreen: undefined,
          secondaryScreen: undefined,
          remark: undefined,
          authId: undefined
        }
        return request({
          url: '/app-api/ecm/app/pos-device/bindPosDevice',
          method: 'post',
          data: utils.filterFormData(data, querData),
          custom: {
            showSuccess: true,
            loadingMsg: "绑定设备中",
            successMsg: "绑定成功",
          },
        })
      },
      getDeviceStatus (snNo) {
        return request({
          url: '/app-api/ecm/app/pos-device/getDeviceStatus',
          method: 'get',
          params: { snNo },
        })
      },
    },
    posConfig: {
      // 获取收银机参数配置
      getByMerchantId (merchantId) {
        return request({
          url: '/app-api/ecm/app/pos-config/getByMerchantId',
          method: 'get',
          params: {
            merchantId
          },
          custom: {
            showLoading: false
          }
        })
      }
    },
    posSecondScreenConfig: {
      getSecondImgUrls (merchantId) {
        return request({
          url: '/app-api/ecm/app/pos-second-screen-config/getSecondImgUrls',
          method: 'get',
          params: {
            merchantId
          },
          custom: {
            showLoading: false
          }
        })
      }
    }
  },
  system: {

    authLogin (data) {
      const querData = {
        username: undefined,
        password: undefined,
      }
      return request({
        url: '/admin-api/system/auth/login',
        method: 'post',
        data: utils.filterFormData(data, querData),
        custom: {
          showSuccess: true,
          loadingMsg: "登录中",
          successMsg: "登录成功",
        },
        // headers: {
        //   'Content-Type': 'application/x-www-form-urlencoded'
        // }
      })
    },
    authLogout () {
      return request({
        url: '/admin-api/system/auth/logout',
        method: 'post',
        custom: {
          showSuccess: true,
          loadingMsg: "退出登录中",
        },
      })
    },

    getUserInfo (id) {
      return request({
        url: '/app-api/system/user/get',
        method: 'get',
        params: { id: id },
        // headers: {
        //   'tenant-id': useCommonStore().authId
        // }
      })
    },
  },
  erp: {
    salePanelBundle: {
      getByPosId (posId) {
        return request({
          url: '/app-api/erp/app/sale-panel-bundle/getByPosId',
          method: 'get',
          params: { posId },
          // headers: {
          //   'tenant-id': useCommonStore().authId
          // }
        })
      }
    },
    salePanelSkus: {
      selectSkusList (params) {
        return request({
          url: '/app-api/erp/app/sale-panel-skus/selectSkusList',
          method: 'get',
          params,
          // headers: {
          //   'tenant-id': useCommonStore().authId
          // }
          custom: {
            showLoading: false
          }
        })
      }
    },
    getProductSkuList (params) {
      return request({
        url: '/app-api/erp/app/product-sku/queryPosPage',
        method: 'get',
        params: {
          filter: 180,
          recordId: useCommonStoreWithOut().merchantId,
          ...params,
        },
        custom: {
          showLoading: false
        }
        // headers: {
        //   'tenant-id': useCommonStore().authId
        // }
      })
    },
    product: {
      selectPosProductById (params) {

        return request({
          url: '/app-api/erp/app/product/selectPosProductById',
          method: 'get',
          params,
          // headers: {
          //   'tenant-id': useCommonStore().authId
          // }
        })
      }
    },
    productSku: {
      // merchantId,inputCode
      // inputCode  扫码识别到的条码或者选定商品的skuId
      selectProductSkuByCombination (params, custom = { showLoading: false }) {
        return request({
          url: '/app-api/erp/app/product-sku/selectProductSkuByCombination',
          method: 'get',
          params: {
            merchantId: useCommonStoreWithOut().merchantId,
            ...params
          },
          custom
          // headers: {
          //   'tenant-id': useCommonStore().authId
          // }
        })
      }
    }
  }
}
